Skip to content

Conversation

@vishwa-uber
Copy link
Contributor

@vishwa-uber vishwa-uber commented Jul 22, 2025

Sleep Workflow Sample

This sample workflow demonstrates how to use the workflow.Sleep function in Cadence workflows. The sleep functionality allows workflows to pause execution for a specified duration before continuing with subsequent activities.

Sample Description

The sample workflow:

  • Takes a sleep duration as input parameter
  • Uses workflow.Sleep to pause workflow execution for the specified duration
  • Executes a main activity after the sleep period completes
  • Demonstrates proper error handling for sleep operations
  • Shows how to configure activity options for post-sleep activities

The workflow is useful for scenarios where you need to:

  • Implement delays or timeouts in workflow logic
  • Wait for external events or conditions
  • Implement retry mechanisms with exponential backoff
  • Create scheduled or periodic workflows

Key Components

  • Workflow: sleepWorkflow demonstrates the sleep functionality with activity execution
  • Activity: mainSleepActivity is executed after the sleep period
  • Sleep Duration: Configurable duration (default: 30 seconds) passed as workflow input
  • Test: Includes unit tests to verify sleep and activity execution

Steps to Run Sample

  1. You need a cadence service running. See details in cmd/samples/README.md

  2. Run the following command to start the worker:

    ./bin/sleep -m worker
    
  3. Run the following command to execute the workflow:

    ./bin/sleep -m trigger
    

Local Test Results:

Screen.Recording.2025-07-29.at.12.01.58.PM.mov

@davidporter-id-au davidporter-id-au merged commit b86320d into master Jul 29, 2025
2 checks passed
@vishwa-uber vishwa-uber deleted the workflow_sleep branch July 29, 2025 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants